Advertisement
S3mpx

mine

May 20th, 2024
500
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.39 KB | None | 0 0
  1. -- Define the ores to search for
  2. local targetOres = {
  3.     ["minecraft:iron_ore"] = true,
  4.     ["minecraft:lead_ore"] = true,
  5.     ["minecraft:nickel_ore"] = true
  6. }
  7.  
  8. -- Function to detect the block in front of the turtle
  9. local function detectBlock()
  10.     local success, data = turtle.inspect()
  11.     if success and targetOres[data.name] then
  12.         return true
  13.     end
  14.     return false
  15. end
  16.  
  17. -- Function to detect the block above the turtle
  18. local function detectBlockUp()
  19.     local success, data = turtle.inspectUp()
  20.     if success and targetOres[data.name] then
  21.         return true
  22.     end
  23.     return false
  24. end
  25.  
  26. -- Function to detect the block below the turtle
  27. local function detectBlockDown()
  28.     local success, data = turtle.inspectDown()
  29.     if success and targetOres[data.name] then
  30.         return true
  31.     end
  32.     return false
  33. end
  34.  
  35. -- Function to mine in front of the turtle
  36. local function mineForward()
  37.     while turtle.detect() do
  38.         turtle.dig()
  39.     end
  40.     turtle.forward()
  41. end
  42.  
  43. -- Function to mine up
  44. local function mineUp()
  45.     while turtle.detectUp() do
  46.         turtle.digUp()
  47.     end
  48.     turtle.up()
  49. end
  50.  
  51. -- Function to mine down
  52. local function mineDown()
  53.     while turtle.detectDown() do
  54.         turtle.digDown()
  55.     end
  56.     turtle.down()
  57. end
  58.  
  59. -- Function to mine around the turtle (front, left, right, up, down)
  60. local function mineAround()
  61.     -- Check front
  62.     if detectBlock() then
  63.         mineForward()
  64.         mineAround()
  65.         turtle.back()
  66.     end
  67.    
  68.     -- Check left
  69.     turtle.turnLeft()
  70.     if detectBlock() then
  71.         mineForward()
  72.         mineAround()
  73.         turtle.back()
  74.     end
  75.     turtle.turnRight()
  76.  
  77.     -- Check right
  78.     turtle.turnRight()
  79.     if detectBlock() then
  80.         mineForward()
  81.         mineAround()
  82.         turtle.back()
  83.     end
  84.     turtle.turnLeft()
  85.  
  86.     -- Check up
  87.     if detectBlockUp() then
  88.         mineUp()
  89.         mineAround()
  90.         turtle.down()
  91.     end
  92.  
  93.     -- Check down
  94.     if detectBlockDown() then
  95.         mineDown()
  96.         mineAround()
  97.         turtle.up()
  98.     end
  99. end
  100.  
  101. -- Main mining function
  102. local function mineTunnel(length)
  103.     for i = 1, length do
  104.         mineForward()
  105.         mineAround()
  106.     end
  107. end
  108.  
  109. -- Main program
  110. print("Starting mining program...")
  111. local tunnelLength = 20  -- Adjust as needed
  112. mineTunnel(tunnelLength)
  113. print("Mining program completed.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement